package cn.itcast.service.impl;


import cn.itcast.mapper.WeatherMapper;
import cn.itcast.pojo.Weather;

import cn.itcast.service.WeatherService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.fegin.XioaHuaClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;


import java.util.List;

@Service
@Slf4j
public class WeatherServiceImpl extends ServiceImpl<WeatherMapper, Weather> implements WeatherService {

//    @Autowired
//    private RestTemplate restTemplate;

    @Autowired
    private WeatherMapper weatherMapper;

    @Autowired
    private XioaHuaClient xioaHuaClient;

    @Override
    public void saveWeather(String cityName) {
        //String forObject = restTemplate.getForObject("http://weather-service/weather/getCityWeatherInfo/" + cityName, String.class);
        String info = xioaHuaClient.getCityWeatherInfo(cityName);
        List<Weather> list = JSONObject.parseArray(info, Weather.class);
        System.out.println(list);
        weatherMapper.insert(list.get(0));
    }
}
